package org.krayne.swivel.list;

import javax.swing.JCheckBox;

/**
 * A {@code CheckboxListItem} is meant to be the type of item you put into a
 * {@code CheckboxList}. It is basically a {@code JCheckBox} that carries
 * with it an object.
 *  
 * @author dhsu
 *
 * @param <E> any type
 */
public class CheckboxListItem<E> extends JCheckBox {
    private static final long serialVersionUID = 8261554956767350169L;
    private static final boolean DEFAULT_IS_CHECKED = false;
    private final E item;
    
    /**
     * Constructs a checkbox list item with the specified associated object.
     * 
     * @param item the associated object
     */
    public CheckboxListItem(E item) {
        this(item, DEFAULT_IS_CHECKED);
    }
    
    /**
     * Constructs a checkbox list item with the specified associated object
     * and whether the item is initially checked or not.
     * 
     * @param item the associated object
     * @param isChecked whether the list item is initially checked or not
     */
    public CheckboxListItem(E item, boolean isChecked) {
        this.item = item;
        this.setSelected(isChecked);
        this.setText(item.toString());
    }
    
    /**
     * Gets the associated object.
     * 
     * @return the assocated object
     */
    public E getItem() {
        return item;
    }
}
